
float alphaCutOff = 0.2;
sampler TextureSampler : register(s0);
float4 colorIn;

float4 alphaClamp(float4 color)
{
	if(color.a < alphaCutOff)
		color.rgba = 0;
	else
	{
		float b = 1-color.a /2 ;
		color.rgb = colorIn * b;
		color.a = 1;
	}

	return color;
}

float4 main(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{


	float2 ySmpl = texCoord + float2(0.0f, -0.005f);
	float2 xSmpl = texCoord + float2(0.00f, 0.0f);

     // Look up the texture and normalmap values.
    float4 tex = tex2D(TextureSampler, texCoord);
	float4 ySmplTex = tex2D(TextureSampler, ySmpl);
	float4 xSmplTex = tex2D(TextureSampler, xSmpl);

	/*tex.r = (tex.r + ySmplTex.r + xSmplTex.r) * 0.33333f;
	tex.g = (tex.g + ySmplTex.g + xSmplTex.g) * 0.33333f;
	tex.b = (tex.b + ySmplTex.b + xSmplTex.b) * 0.33333f;*/



	tex = alphaClamp(tex);
	//xSmplTex = alphaClamp(xSmplTex);
	//ySmplTex = alphaClamp(ySmplTex);
	/*
	float3 posA = float3(0.0f, 0.0f, 1.0f);
	float3 posB = float3(0.0f, 0.0f, ySmplTex.a);
	float3 posC = float3(0.0f, 0.0f, xSmplTex.a);
	posB = normalize(posB);
	posC = normalize(posC);

	float3 normal = -cross(normalize(posB - posA), normalize(posC - posA));
	//normal.b = 1;
	normal = normalize(normal);
	*/
	tex.rgb -= ySmplTex.rgb - xSmplTex.rgb;
//	tex.rgb = lerp(tex.rgb,1,0.8) * color;

	tex.rgb = clamp(tex.rgb + colorIn,0.0f,1.0f);

	if(tex.a < 0.2f)
	{
		return float4(0,0,0,0);
	}
	tex.a = tex.r;

    return tex;
}

technique alphaTest
{
    pass Pass1
    {
        PixelShader = compile ps_2_0 main();
    }
}
